home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / tools / zmc3v078 / zmc3v078.lzh / SRCSV078.LZH / MAKEZMD3.C < prev    next >
C/C++ Source or Header  |  2000-02-27  |  49KB  |  1,721 lines

  1. /* ==========================================
  2.      @ series (@v, @b, @r, ... ) conversion
  3.      and... many subroutines
  4.    ========================================== */
  5.  
  6.  
  7. #include <stdio.h>
  8. #include <stdlib.h>
  9. #include <string.h>
  10. #include "etc.h"
  11. #include "makezmd2.h"
  12. #include "parsesub.h"
  13. #include "velo.h"
  14. #include "68lib.h"
  15. #include "arcc.h"
  16. #include "bracket.h"
  17.  
  18. #include "structs.h"
  19. #include "structs2.h"
  20. int checkInternalDevice(TRKCHINF *trkdata, BYTE Trk);
  21. void initTrkInf(TRKINF *trkinf, COMMONINF *cominf);
  22. void initTrkInf2(TRKINF *trkinf, int trk);
  23. void freeTrkInf(TRKINF *trkinf,int trk);
  24. void copyTrkInf(TRKINF *des, TRKINF *src);
  25. UBYTE *makeZmdAtmark(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  26.                         TRKINF *trkinf,COMMONINF *cominf);
  27. UBYTE *makeZmdLoop1(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  28.                         TRKINF *trkinf);
  29. UBYTE *makeZmdEigDepthSub(UBYTE *zms,
  30.                         VELOETCVAR *vv, BYTE *pos,BYTE *num,BYTE supplementmode);
  31. UBYTE *makeZmdVeloSeq(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  32.                         TRKINF *trkinf);
  33. UBYTE *makeZmdQuantize(UBYTE *zms, int mode, const BYTE target[],
  34.                         TRKINF *trkinf);
  35. UBYTE *makeZmdManyParas(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
  36.                         DWORD line_,char *linebuf,
  37.                         UBYTE com, UBYTE omitcode,BYTE maxparas,
  38.                         BYTE parabytes,BYTE omitflg,
  39.                         char *errmes1, char *errmes2,char *errmes3);
  40. UBYTE *makeZmdManyParas2(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
  41.                         DWORD line_,char *linebuf_,
  42.                         UBYTE com, BYTE maxparas,
  43.                         const BYTE parabytes[],BYTE omitflg,BYTE ARCCno,
  44.                         int space, int times,const int mustover0,
  45.                         char *errmes1, char *errmes2,char *errmes3);
  46. UBYTE *makeZmdManyParas2A(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
  47.                         DWORD line_,char *linebuf_,
  48.                         UBYTE com, BYTE maxparas,
  49.                         const BYTE parabytes[],BYTE omitflg, BYTE ARCCno,
  50.                         int mode,
  51.                         char *errmes1, char *errmes2,char *errmes3);
  52. UBYTE *makeZmdChord(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  53.                     TRKINF *trkinf,char extmode,COMMONINF *cominf);
  54. CHKCHORD *addNextChkChord(CHKCHORD *c, BYTE note, DWORD gate, DWORD total);
  55. void rewriteGateinChord(TRKCHINF *trkdata, TRKINF *trkinf,
  56.                             int Trk,CHKCHORD *c, UWORD gate);
  57. CHKCHORD *killChord(CHKCHORD *c);
  58. UBYTE *makePortament(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  59.                         TRKINF *trkinf,COMMONINF *cominf,const char endchar);
  60. int checkCommonCommand(UBYTE *zms_,int notes,BYTE note[],UWORD step_,
  61.                         DWORD line_,char *linebuf_, COMMONINF *cominf);
  62.  
  63.  
  64. extern DWORD line;
  65. extern char *linebuf;
  66. extern LINEDATA *ld;
  67.  
  68. int checkInternalDevice(TRKCHINF *trkdata, BYTE Trk) {    /* thanks to Mamiya */
  69.     if (trkdata[Trk].chtype == 0) return 1;                            /* OPM */
  70.     if (trkdata[Trk].chtype == 1) return 2;                            /* ADPCM */
  71. #ifdef A
  72.     if (25 <= trkdata[Trk].ch && trkdata[Trk].ch <= 31) return 2;    /* PCM8 */
  73. #endif
  74.     return 0 ;                                                        /* MIDI */
  75. }
  76.  
  77.  
  78. void initTrkInf(TRKINF *trkinf, COMMONINF *cominf)
  79. {
  80.     int j;
  81.  
  82.     trkinf->total = 0;
  83.     trkinf->noteon = 0;
  84.     trkinf->setdev = 0;
  85.  
  86.     trkinf->volmode = 0;                /* 128 mode */
  87.  
  88.     trkinf->velocity = (VELOETCVAR*)emalloc(sizeof(VELOETCVAR) * 1,"trkinf->velocity");
  89.     trkinf->velocity[0].var[0] = 127;
  90.     trkinf->velocity[0].var[1] = 0;
  91.     trkinf->velozpos = 0;
  92.     trkinf->veloznum = 0;
  93.     trkinf->velou.var[0] = 127;
  94.     trkinf->velou.var[1] = 0;
  95.     trkinf->velou.relflg[0] = 0;    /* velocity sequences flag: 1:now on use 0: non use */
  96.  
  97.     trkinf->relvelo = 0;
  98.     trkinf->nowvelo = 127;
  99.     trkinf->veloseqsw = 1;
  100.  
  101.     trkinf->mod[0].var[0] = 0;
  102.     trkinf->arcc[0].var[0] = 127;
  103.     trkinf->mod[0].relflg[0] = 0;
  104.     trkinf->arcc[0].relflg[0] = 0;
  105.  
  106.     trkinf->volofst = 0;
  107.     trkinf->veloofst = 0;
  108.     trkinf->arccofst[0] = trkinf->arccofst[0] = 
  109.     trkinf->arccofst[0] = trkinf->arccofst[0] = 0;
  110.  
  111.     trkinf->gtreso = cominf->gtreso;
  112.     trkinf->quantize = (VELOETCVAR*)emalloc(sizeof(VELOETCVAR) * 1,"trkinf->quantize");
  113.     trkinf->quantize[0].var[0] = cominf->gtreso;
  114.     trkinf->quantize[0].relflg[0] = 0;
  115.     trkinf->quantize[0].relflg[1] = -1;
  116.     trkinf->quantizepos = 0;
  117.     trkinf->quantizenum = 1;
  118.  
  119.     trkinf->octave = 4;
  120.     trkinf->Step = 48;
  121.     trkinf->laststep = 48;
  122.     trkinf->velozpos = 0;
  123.     trkinf->veloznum = 0;
  124.     trkinf->modpos = 0;
  125.     trkinf->modnum = 0;
  126.     trkinf->arccpos = 0;
  127.     trkinf->arccnum = 0;
  128.     /* trkinf->vol = 64; */
  129.     trkinf->relvol = 1;
  130.     trkinf->randvelotype  = 0;
  131.     trkinf->randvelopower = 0;
  132.     for (j = 0; j < 12; j++) {
  133.         trkinf->ksign[j] = 0;
  134.     }
  135.     trkinf->transpose = 0;
  136.     trkinf->fadeout = 0;
  137.     trkinf->abdelay = 0;
  138.     trkinf->pdelay = 0;
  139.     trkinf->cdelay = 0;
  140.     trkinf->ptime = 0;
  141.     trkinf->spvelomode = 0;
  142.     trkinf->renpnotes = 0;
  143.     trkinf->cominf = cominf;
  144.  
  145.     trkinf->segno = 0;
  146.     trkinf->coda = 0;
  147.  
  148.     trkinf->back_repeat = 0;
  149.  
  150.     trkinf->bankh = trkinf->bankh = 0;
  151.  
  152.     trkinf->echoitv = 0;
  153.     trkinf->echodec = 0;
  154.     trkinf->echolp  = 1;
  155. }
  156.  
  157. void initTrkInf2(TRKINF *trkinf, int trk)
  158. {
  159.     char s[32];
  160.  
  161.     sprintf(s,"trkinf[%d]->l_initTrkInf2",trk);
  162.     trkinf->l = (LOOPDATA*)emarealloc( trkinf->l, sizeof(LOOPDATA) * 1,s);
  163.     sprintf(s,"trkinf[%d]->d_initTrkInf2",trk);
  164.     trkinf->d = (LOOPDATA*)emarealloc( trkinf->d, sizeof(LOOPDATA) * 1,s);
  165.     sprintf(s,"trkinf[%d]->r_initTrkInf2",trk);
  166.     trkinf->r = (RENP*)emarealloc( trkinf->r, sizeof(RENP) * 1,s);
  167.     sprintf(s,"trkinf[%d]->s_initTrkInf2",trk);
  168.     trkinf->s = (CHKSTEP*)emarealloc( trkinf->s, sizeof(CHKSTEP) * 1,s);
  169.     sprintf(s,"trkinf[%d]->c_initTrkInf2",trk);
  170.     trkinf->c = (CHKCHORD*)emarealloc( trkinf->c, sizeof(CHKCHORD) * 1,s);
  171. #ifdef A
  172.     trkinf->l = (LOOPDATA*)emalloc(sizeof(LOOPDATA) * 1,"trkinf->l");
  173.     trkinf->d = (LOOPDATA*)emalloc(sizeof(LOOPDATA) * 1,"trkinf->d");
  174.     trkinf->r = (RENP*)emalloc(sizeof(RENP) * 1,"trkinf->r");
  175.     trkinf->s = (CHKSTEP*)emalloc(sizeof(CHKSTEP) * 1,"trkinf->s");
  176. #endif
  177. /*
  178.         trkinf->b = (BACK*)emalloc(sizeof(BACK) * 1);
  179.         trkinf->e = (EVENT*)emalloc(sizeof(EVENT) * 1);
  180. */
  181.         trkinf->l->next = trkinf->l->prev = NULL;
  182.         trkinf->l->loopmode = 0;
  183.         trkinf->d->next = trkinf->d->prev = NULL;
  184.         trkinf->d->looptime = 0;
  185.         trkinf->r->next = trkinf->r->prev = NULL;
  186.         trkinf->s->next = trkinf->s->prev = NULL;
  187.         trkinf->c->next = trkinf->c->prev = NULL;
  188. /*
  189.         trkinf->b->next = trkinf->b->prev = NULL;
  190.         trkinf->e->next = trkinf->e->prev = NULL;
  191. */
  192.         trkinf->r->step = -1;
  193.         trkinf->r->pflg = 0;
  194.         trkinf->s->step = 0;
  195.         trkinf->c->note = -1;
  196.         trkinf->c->gatepos = -1;
  197. /*
  198.         trkinf->e->code = 0;
  199. */
  200. }
  201.  
  202.  
  203. void freeTrkInf(TRKINF *trkinf, int trk)
  204. {
  205.     char s[32];
  206.     sprintf(s,"trkinf[%d]->velocity",trk);
  207.     efree(trkinf->velocity,s);
  208.     trkinf->velocity = NULL;
  209.     sprintf(s,"trkinf[%d]->quantize",trk);
  210.     efree(trkinf->quantize,s);
  211.     trkinf->quantize = NULL;
  212.  
  213.     sprintf(s,"trkinf[%d]->l",trk);
  214.     efree(trkinf->l,s);
  215.     trkinf->l = NULL;
  216.     sprintf(s,"trkinf[%d]->d",trk);
  217.     efree(trkinf->d,s);
  218.     trkinf->d = NULL;
  219.     sprintf(s,"trkinf[%d]->r",trk);
  220.     efree(trkinf->r,s);
  221.     trkinf->r = NULL;
  222.     sprintf(s,"trkinf[%d]->s",trk);
  223.     efree(trkinf->s,s);
  224.     trkinf->s = NULL;
  225.     sprintf(s,"trkinf[%d]->c",trk);
  226.     efree(trkinf->c,s);
  227.     trkinf->c = NULL;
  228.  
  229.     
  230.  
  231. /*
  232.     free(trkinf->b);
  233.     free(trkinf->e);
  234. */
  235. }
  236.  
  237. void copyTrkInf(TRKINF *des, TRKINF *src)
  238. {
  239.     int i;
  240.     BYTE num;
  241.  
  242.     efree(des->velocity,"des->velocity");
  243.     efree(des->quantize,"des->quantize");
  244.  
  245.     {
  246.         LOOPDATA *l, *d;
  247.         RENP *r;
  248.         CHKSTEP *s;
  249.         CHKCHORD *c;
  250.  
  251.         l = des->l;
  252.         d = des->d;
  253.         r = des->r;
  254.         s = des->s;
  255.         c = des->c;
  256.  
  257.         *des = *src;
  258.  
  259.         des->l = l;
  260.         des->d = d;
  261.         des->r = r;
  262.         des->s = s;
  263.         des->c = c;
  264.     }
  265.  
  266.     num = des->veloznum ? des->veloznum : 1;
  267.     des->velocity = emalloc(sizeof(VELOETCVAR) * num,"des->velocity");
  268.     for (i = 0; i < num; i++) {
  269.         des->velocity[i] = src->velocity[i];
  270.     }
  271.  
  272.     num = des->quantizenum ? des->quantizenum : 1;
  273.     des->quantize = emalloc(sizeof(VELOETCVAR) * num,"des->quantize");
  274.     for (i = 0; i < num; i++) {
  275.         des->quantize[i] = src->quantize[i];
  276.     }
  277. }
  278.  
  279.  
  280.  
  281. UBYTE *makeZmdAtmark(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  282.                         TRKINF *trkinf,COMMONINF *cominf)
  283. {
  284.     UBYTE *zms_ = zms + 1;
  285.     DWORD tmpDWORD;
  286.     int trk,err;
  287.     DWORD line_ = line;
  288.     char *linebuf_ = linebuf;
  289.     LINEDATA *ld_ = ld;
  290.  
  291.     switch (*zms++) {
  292.         case 'a':    case 'A':                /* @a */
  293.             zms = makeARCClevel0(zms, trkdata, target, trkinf, 0, -2);
  294.             break;
  295.         case 'b':    case 'B':                /* @b */
  296.             zms = makeZmdBend(zms, trkdata, trkinf, target, 1);
  297.             break;
  298.         case 'c':    case 'C':                /* @c */
  299.             {
  300.                 const BYTE parabytes[3] = {1,1,1};
  301.                 zms = makeZmdManyParas2A(zms,trkdata,target,line_,linebuf_,
  302.                                         0xF7, 3, parabytes, 1, 0, -1,
  303.                                         "@c: too many parameters.",
  304.                                         "@c can't use relational parameters.",
  305.                                         "");
  306.             }
  307.             break;
  308.         case 'd':    case 'D':                /* @d */
  309. /*OK*/        zms = makeZmdDamper(zms, trkdata, target, 0);
  310.             break;
  311.         case 'e':    case 'E':                /* @e */
  312. /*OK*/        zms = makeZmdEffect(zms,trkdata,target);
  313.             break;
  314.         case 'g':    case 'G':                /* @g */
  315. /*OK*/        zms = makeZmdBendRange(zms, trkdata, target);
  316.             break;
  317.         case 'h':    case 'H':                /* @h */
  318. /*OK*/
  319.             {
  320.                 UBYTE cmd[] = {0xE4, 0xE7};
  321.                 int i;
  322.  
  323.                 for (i = 0; i < 2; i++) {
  324.                     int err;
  325.                     DWORD p;
  326.                     zms = getnum2(zms, &p, &err);
  327.                     if (err > 0) {
  328.                         zmserror("@H parameter error.",line,linebuf,zms,0,1);
  329.                     } else if (!err) {
  330.                         int trk;
  331.                         for (trk = 0; target[trk] >= 0; trk++) {
  332.                             const int Trk = target[trk];
  333.                             *trkdata[Trk].zmd++ = cmd[i];
  334.                             if (i == 1) {
  335.                                 *trkdata[Trk].zmd++ = 0;
  336.                             }
  337.                             putWord(trkdata[Trk].zmd, 1);
  338.                             putWord(trkdata[Trk].zmd + 2, p);
  339.                             trkdata[Trk].zmd += 4;
  340.                         }
  341.                     }
  342.                     zms = skipSpc(zms);
  343.                     if (*zms == ',') {
  344.                         zms += 1;
  345.                     } else {
  346.                         break;
  347.                     }
  348.                 }
  349.             }
  350.             break;
  351.         case 'i':    case 'I':                /* @i */
  352. /*OK*/        {
  353.                 int trk;
  354.                 for (trk = 0; target[trk] >= 0; trk++) {
  355.                     trkinf[target[trk]].setdev = 1;
  356.                 }
  357.             }
  358.             zms = makeZmdInstrumentId(zms,trkdata,target);
  359.             break;
  360.         case 'j':    case 'J':                /* @j */
  361. /*OK*/        zms = makeZmdTieMode(zms, trkdata, target);
  362.             break;
  363.         case 'k':    case 'K':                /* @k */
  364.             zms = makeZmdBend(zms, trkdata, trkinf, target, 0);
  365.             break;
  366.         case 'l':    case 'L':                /* @l */
  367. /*OK*/        zms = getnum2(zms_, &tmpDWORD, &err);
  368.             if (err < 0) {
  369.                 zmserror("@l can't omit its parameter.",line_,linebuf_,zms_,0,1);
  370.             }
  371.             for (trk = 0; target[trk] >= 0; trk++) {
  372.                 trkinf[target[trk]].Step = tmpDWORD;
  373.             }
  374.             break;
  375.         case 'm':    case 'M':                /* @m */
  376.             for (trk = 0; target[trk] >= 0; trk++) {
  377.                 int i;
  378.                 VELOETCVAR v[17];
  379.                 const int Trk = target[trk];
  380.  
  381.                 line = line_;
  382.                 ld = ld_;
  383.                 zms = makeZmdEigDepthSub(zms_,
  384.                                             v,&trkinf[Trk].modpos,
  385.                                             &trkinf[Trk].modnum,1);
  386.  
  387.                 if (trkinf[Trk].modnum == 0) {
  388. /*OK*/                *trkdata[Trk].zmd++ = 0xE2;    /* mod sw off */
  389.                     *trkdata[Trk].zmd++ = 0x00;
  390.                     *trkdata[Trk].zmd++ = 0x00;
  391.                 } else if (trkinf[Trk].modnum == 1) {
  392. /*OK*/
  393. #ifdef A
  394.                     /* if (v[0].var[0] == 0) { */
  395.                         *trkdata[Trk].zmd++ = 0xE2;    /* mod sw off */
  396.                         *trkdata[Trk].zmd++ = 0x00;
  397.                         *trkdata[Trk].zmd++ = 0x00;
  398.                     /* } else { */
  399. #endif
  400.                         *trkdata[Trk].zmd++ = 0xE2;    /* mod single */
  401.                         *trkdata[Trk].zmd++ = 0x01;
  402.                         *trkdata[Trk].zmd++ = 0x01;
  403.                         putWord(trkdata[Trk].zmd, v[0].var[0]);
  404.                         trkdata[Trk].zmd += 2;
  405.                     /* } */
  406.                 } else {                                /* mod dep1/8 */
  407. /*OK*/                UBYTE *zmd__;
  408.                     UBYTE flg = 0;
  409.  
  410.                     *trkdata[Trk].zmd++ = 0xE2;
  411.                     *trkdata[Trk].zmd++ = 0xFF;
  412.                     zmd__ = trkdata[Trk].zmd;
  413.                     trkdata[Trk].zmd++;
  414.                     for (i = 0; i < trkinf[Trk].modnum; i++) {
  415.                         trkinf[Trk].mod[i].var[0]    = v[i].var[0];
  416.                         trkinf[Trk].mod[i].relflg[0] = v[i].relflg[0];
  417.  
  418.                         flg >>= 1;
  419.                         if (v[i].relflg[0] != 2) {
  420.                             putWord(trkdata[Trk].zmd,v[i].var[0]);
  421.                             trkdata[Trk].zmd += 2;
  422.                             flg |= 0x80;
  423.                         }
  424. #ifdef A
  425.                         if (v[i].relflg[0] != 2) {
  426.                             flg |= 0x80;
  427.                         }
  428. #endif
  429.                     }
  430.                     for (i = trkinf[Trk].modnum; i < 8; i++) {
  431.                         trkinf[Trk].mod[i].var[0]    = 0;
  432.                         trkinf[Trk].mod[i].relflg[0] = 2;
  433. /*    
  434.                         putWord(trkdata[Trk].zmd,0);
  435.                         trkdata[Trk].zmd += 2;
  436. */
  437.                         flg >>= 1;
  438.                         flg &= 0x7F;
  439.                     }
  440.                     *zmd__ = flg;
  441.                 }
  442.             }
  443.             break;
  444.         case 'n':    case 'N':                        /* @n : channel change */
  445. /*OK*/        zms = getnum2(zms, &tmpDWORD, &err);
  446.             if (err < 0) {
  447.                 zmserror("@n can't omit its parameter.",line_,linebuf_,zms_,0,1);
  448.             }
  449.             for (trk = 0; target[trk] >= 0; trk++) {
  450.                 const int Trk = target[trk];
  451.                 UWORD dev,ch;
  452.  
  453.                 if (tmpDWORD <= 8) {
  454.                     dev = 0;
  455.                     ch = tmpDWORD;
  456.                 } else if (tmpDWORD == 9) {
  457.                     dev = 1;
  458.                     ch = 0;
  459.                 } else if (tmpDWORD <=25) {
  460.                     dev = 0x8000;
  461.                     ch = tmpDWORD - 10;
  462.                 } else if (tmpDWORD < 32) {
  463.                     dev = 1;
  464.                     ch = tmpDWORD - 26 + 1;
  465.                 } else {
  466.                     dev = 0x8000 + (tmpDWORD - 33) / 16;
  467.                     ch = (tmpDWORD - 33) % 16;
  468.                 }
  469.  
  470.                 *trkdata[Trk].zmd++ = 0xCC;
  471.                 putWord(trkdata[Trk].zmd, dev);
  472.                 putWord(trkdata[Trk].zmd + 2, ch);
  473.                 trkdata[Trk].zmd += 4;
  474.                 if (trkinf[Trk].noteon) {
  475.                     trkdata[Trk].chtype = dev;
  476.                     trkdata[Trk].ch = ch;
  477.                 }
  478.             }
  479.             break;
  480.         case 'p':    case 'P':                /* @p */
  481.             zms = makeZmdPanpot(zms, trkdata, target, 0);
  482.             break;
  483.         case 'q':    case 'Q':                /* @q */
  484. /*ok*/        zms = makeZmdQuantize(zms, 0, target, trkinf);
  485.             break;
  486.         case 'r':    case 'R':                /* @r */
  487. /*OK*/        zms = makeZmdTrackMode(zms, trkdata, trkinf, target);
  488.             break;
  489.         case 's':    case 'S':                /* @s */
  490. /*OK*/
  491.             {
  492.                 UBYTE cmd[] = {0xE3, 0xE6};
  493.                 int i;
  494.  
  495.                 for (i = 0; i < 2; i++) {
  496.                     int err;
  497.                     DWORD p;
  498.                     zms = getnum2(zms, &p, &err);
  499.                     if (err > 0 || (err == 0 && p == 0)) {
  500.                         zmserror("@S parameter error.",line,linebuf,zms,0,1);
  501.                     } else if (!err) {
  502.                         int trk;
  503.                         for (trk = 0; target[trk] >= 0; trk++) {
  504.                             const int Trk = target[trk];
  505.  
  506.                             *trkdata[Trk].zmd++ = cmd[i];
  507.                             if (i == 1) {
  508.                                 *trkdata[Trk].zmd++ = 0x00;
  509.                             }
  510.                             *trkdata[Trk].zmd++ = 1;
  511.                             putWord(trkdata[Trk].zmd, p * 2);
  512.                             trkdata[Trk].zmd += 2;
  513.                         }
  514.                     }
  515.                     zms = skipSpc(zms);
  516.                     if (*zms == ',') {
  517.                         zms += 1;
  518.                     } else {
  519.                         break;
  520.                     }
  521.                 }
  522.             }
  523.             break;
  524.         case 'u':    case 'U':                /* @u */
  525. /*OK*/        zms = setMMLatU(zms,trkdata,trkinf,target, 0);
  526.             break;
  527.         case 'v':    case 'V':                /* @v */
  528.             zms = makeZmdVolume(zms, trkdata, target, trkinf, 0);
  529.             break;
  530.         case 'w':    case 'W':                /* @w */
  531. /*OK*/        zms = makeZmdTrackDelay(zms, trkdata, target, trkinf, cominf, 0);
  532.             break;
  533.         case 'x':    case 'X':                /* @x */
  534.             zms = makeZmdExclusive(zms, trkdata, target, 0);
  535.             break;
  536.         case 'y':    case 'Y':                /* @y */
  537.             zms = makeZmdSetNRPN(zms, trkdata, target);
  538.             break;
  539.         case 'z':    case 'Z':                /* @z */    /* thanks to Mamiya */
  540.             for (trk = 0; target[trk] >= 0; trk++) {
  541.                 const int Trk = target[trk];
  542.                 int i = 0 ;
  543.                 DWORD z = trkinf[Trk].velou.var[0];
  544.                 line = line_;
  545.                 ld = ld_;
  546.  
  547.                 zms = getnum2(zms_, &tmpDWORD, &err);
  548.                 /*zms = skipSpc(zms);*/
  549.                 if (err < 0 && *zms != ',') {
  550.                     *trkdata[Trk].zmd++ = 0xBE;
  551.                     *trkdata[Trk].zmd++ = 0x00;
  552.                     continue;
  553.                 }
  554.                 *trkdata[Trk].zmd++ = 0xE3;
  555.                 line = line_;
  556.                 ld = ld_;
  557.                 zms = zms_ - 1 ;
  558.                 do {
  559.                     int r = 0 ;
  560.                     zms = skipSpcCr(zms + 1);
  561.                     if (*zms == '+' || *zms == '-') r = 1 ;
  562.                     zms = getnum2(zms, &tmpDWORD, &err);
  563.                     if (err < 0) {
  564.                         *trkdata[Trk].zmd++ = -1 ;
  565.                     } else if (r) {
  566.                         z += tmpDWORD ;
  567.                         z = (z < 0) ? z : ((z > 127) ? 127 : z) ;
  568.                         *trkdata[Trk].zmd++ = z;
  569.                     } else {
  570.                         *trkdata[Trk].zmd++ = z = tmpDWORD;
  571.                     }
  572.                     /*zms = skipSpc(zms);*/
  573.                 } while (++i < 8 && *zms == ',') ;
  574.                 while (i++ < 8) *trkdata[Trk].zmd++ = -1;
  575.                 if (*zms == ',') {
  576.                     zmserror("@z: too many ','.",line,linebuf_,zms,2,1);
  577.                     zms++ ;
  578.                 }
  579.             }
  580.             break;
  581. /* (BEGIN FM/ADPCMsupport by Mamiya */
  582.         case 't':    case 'T':                /* @t */
  583.             zms = makeZmdTempo(zms, trkdata, target, 2);
  584. #ifdef A
  585.             for (trk = 0; target[trk] >= 0; trk++) {
  586.                 const int Trk = target[trk];
  587.                 BYTE rel = 0;
  588.                 line = line_;
  589.                 ld = ld_;
  590.                 zms = skipSpcCr(zms_);
  591.                 if (*zms == '+') {
  592.                     rel = 1;
  593.                 } else if (*zms == '-') {
  594.                     rel = -1;
  595.                 }
  596.                 zms = getnum2(zms, &tmpDWORD, &err);
  597.  
  598.                 if (err < 0) {
  599.                     zmserror("@t must be followed to its parameter.",line_,linebuf_,zms_,0,1);
  600.                 } else {
  601.                     if (!rel) {
  602.                         *trkdata[Trk].zmd++ = 0xC1;
  603.                     } else if (tmpDWORD < 0) {
  604.                         *trkdata[Trk].zmd++ = 0xC2;
  605.                         tmpDWORD = -tmpDWORD;
  606.                     } else {
  607.                         *trkdata[Trk].zmd++ = 0xC2;
  608.                     }
  609.                     putWord(trkdata[Trk].zmd, tmpDWORD);
  610.                     trkdata[Trk].zmd += 2;
  611.                     zmserror("@t will be ignored by many drivers.",line_,linebuf_,zms_ - 1,3,1);
  612.                 }
  613.             }
  614. #endif
  615.             break;
  616.         case 'o':    case 'O':                /* @o */
  617.             zms = getnum2(zms, &tmpDWORD, &err);
  618.             for (trk = 0; target[trk] >= 0; trk++) {
  619.                 if (err < 0) {
  620.                     *trkdata[target[trk]].zmd++ = 0x82;
  621.                 } else {
  622.                     *trkdata[target[trk]].zmd++ = 0xA5;
  623.                     *trkdata[target[trk]].zmd++ = 128 + tmpDWORD ;
  624.                 }
  625.             }
  626.             break;
  627.         case 'f':    case 'F':                /* @f */
  628.             zms = getnum2(zms, &tmpDWORD, &err);
  629.             if (err < 0) {
  630.                 zmserror("@f can't omit its parameter.",line_,linebuf_,zms_,0,1);
  631.             }
  632.             for (trk = 0; target[trk] >= 0; trk++) {
  633.                 *trkdata[target[trk]].zmd++ = 0xA9;
  634.                 *trkdata[target[trk]].zmd++ = tmpDWORD ;
  635.             }
  636.             break;
  637. /* FM/ADPCMsupport by Mamiya END) */
  638.         default:
  639.             zms = makeZmdProgramChange(--zms, trkdata, target);
  640.             break;
  641.     }
  642.     return zms;
  643. }
  644.  
  645.  
  646.  
  647. UBYTE *makeZmdLoop1(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  648.                         TRKINF *trkinf)
  649. {                                                                /* |: |n | */
  650.     int trk;
  651.     UBYTE *zms_ = zms;
  652.     DWORD line_ = line;
  653.     LINEDATA *ld_ = ld;
  654.     char *linebuf_ = linebuf;
  655.  
  656.     switch (*zms++) {
  657.         case '|':
  658.             if (*zms == ':') {                                /* |: */
  659. /*OK*/            DWORD looptime;
  660.                 int err;
  661.  
  662.                 zms = getnum2(++zms,&looptime,&err);
  663.                 if (err >= 0 && looptime <= 0) {
  664.                     zmserror("illegal looptime.",line_,linebuf_,zms_,0,1);
  665.                 }
  666.                 line_ = line;
  667.                 ld_ = ld;
  668.                 if (err < 0) {
  669.                     looptime = 2;
  670.                 }
  671.  
  672.                 for (trk = 0; target[trk] >= 0; trk++) {
  673.                     int Trk = target[trk];
  674.  
  675.                     do {
  676.                         char s[32];
  677.                         sprintf(s,"trkinf[%d].l->next");
  678.                         line  = line_;
  679.                         ld = ld_;
  680.                         recoverSpecialVelocity(trkinf, Trk);
  681.                         if (trkinf[Trk].l->loopmode < 0) {    /* |n .. :| .. |: */
  682.                                                             /* loopmode<0 means "|n ..:| parsed" */
  683.                                                             /* new loop begins */
  684.                             trkinf[Trk].l = trkinf[Trk].l->prev;
  685.                             efree(trkinf[Trk].l->next,"trkinf[Trk].l->next");
  686.                             /* trkinf[Trk].l->next = NULL; */
  687.                         }
  688.  
  689.                         *trkdata[Trk].zmd++ = 0xCD;
  690.                         trkinf[Trk].l->next       = (LOOPDATA*)emalloc(sizeof(LOOPDATA) * 1,s);
  691.                         trkinf[Trk].l->next->prev = trkinf[Trk].l;
  692.                         trkinf[Trk].l             = trkinf[Trk].l->next;
  693.                         trkinf[Trk].l->next       = (LOOPDATA*)NULL;
  694.                         trkinf[Trk].l->loopstart  = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  695.                         trkinf[Trk].l->loopskip   = 0;    /* (UBYTE*)NULL; */
  696.                         putWord(trkdata[Trk].zmd, looptime - 1);
  697.                         trkinf[Trk].l->looptime = looptime;
  698.                         trkinf[Trk].l->looptime2 = 0;
  699.                         putWord(trkdata[Trk].zmd + 2, 0);
  700.                         trkdata[Trk].zmd += 4;
  701.                         trkinf[Trk].l->loopmode   = 0;
  702.                         trkinf[Trk].l->totalstart = trkinf[Trk].total;
  703.                         trkinf[Trk].l->totalmode  = -1;
  704.                             /* totalmode: -1= no |,|n  0 = | 1 = |n */
  705.                     } while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
  706.                 }
  707.             } else {                                        /* |... */
  708.                 DWORD tmpDWORD;
  709.                 int err;
  710.  
  711.                 for (trk = 0; target[trk] >= 0; trk++) {
  712.                     int Trk = target[trk];
  713.  
  714.                     do {
  715.                         if (trkinf[Trk].l->totalmode == -1) {
  716.                             trkinf[Trk].total +=
  717.                                 (trkinf[Trk].total - trkinf[Trk].l->totalstart) *
  718.                                 (trkinf[Trk].l->looptime - 1);
  719.                         }
  720.                         trkinf[Trk].l->totalstart = trkinf[Trk].total;
  721.                     } while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
  722.                 }
  723.  
  724.                 zms = getnum2(zms,&tmpDWORD,&err);
  725.                 line = line_;
  726.                 ld = ld_;
  727.                 if (!err) {                                    /* |n */
  728.                     if (tmpDWORD <= 0) {
  729.                         zmserror("illegal looptime.",line_,linebuf_,zms_,0,1);
  730.                     }
  731.  
  732. /*OK*/                for (trk = 0; target[trk] >= 0; trk++) {
  733.                         int Trk = target[trk];
  734.  
  735.                         do {
  736.                             line = line_;
  737.                             ld = ld_;
  738.                             if (tmpDWORD > trkinf[Trk].l->looptime) {
  739.                                 zmserror("n is too large in |n.",line_,linebuf_,zms_,0,1);
  740.                             }
  741.                             *trkdata[Trk].zmd++ = 0xD8;
  742.                             putWord(trkdata[Trk].zmd, tmpDWORD - 1);
  743.                             trkdata[Trk].zmd += 2;
  744.                             if (trkinf[Trk].l->loopskip) {
  745.                                 zmserror("illegal |n.",line_,linebuf_,zms_,0,1);
  746.                             } else {
  747.                                 const DWORD ls = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  748.  
  749.                                 trkinf[Trk].l->loopmode = tmpDWORD;
  750.  
  751.                                 putDword(trkdata[Trk].zmd, ls - trkinf[Trk].l->loopstart + 2);
  752.                                 trkdata[Trk].zmd += 4;
  753.                                 trkinf[Trk].l->loopskip = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  754.  
  755.                                 putDword(trkdata[Trk].zmd, 0);
  756.                                 trkdata[Trk].zmd += 4;
  757.                             }
  758.                             trkinf[Trk].l->totalmode = 1;
  759.                         } while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
  760.                     }
  761.                 } else if (err < 0) {                        /* |  */
  762. /*OK*/                for (trk = 0; target[trk] >= 0; trk++) {
  763.                         int Trk = target[trk];
  764.  
  765.                         do {
  766.                             line = line_;
  767.                             ld = ld_;
  768.                             if (trkinf[Trk].l->prev == NULL ||
  769.                                 (trkinf[Trk].l->prev->prev == NULL && trkinf[Trk].l->loopmode < 0) ) {
  770.                                 zmserror("illegal |.",line_,linebuf_,zms_,3,1);
  771.                             } else {
  772.                                 *trkdata[Trk].zmd++ = 0xD9;
  773.  
  774.                                 if (trkinf[Trk].l->loopskip) {
  775.                                     zmserror("illegal |.",line_,linebuf_,zms_,0,1);
  776.                                 } else {
  777.                                     const DWORD ls = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  778.                                     /* putWord(trkdata[Trk].zmd, 0); */
  779.                                     putDword(trkdata[Trk].zmd, ls - trkinf[Trk].l->loopstart + 2);
  780.                                     trkdata[Trk].zmd += 4;
  781.                                     trkinf[Trk].l->loopskip   = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  782.                                     putDword(trkdata[Trk].zmd, 0);
  783.                                     trkdata[Trk].zmd += 4;
  784.                                     trkinf[Trk].l->loopmode = 0;
  785.                                 }
  786.                             }
  787.                             trkinf[Trk].l->totalmode = 0;
  788.                         } while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
  789.                     }
  790.                 }
  791.             }
  792.             break;
  793.         case ':':
  794.             if (*zms++ == '|') {                        /* :| */
  795.  
  796. /*tenuki*/        for (trk = 0; target[trk] >= 0; trk++) {
  797.                     int Trk = target[trk];
  798.  
  799.                     do {
  800.                         DWORD tmpDWORD;
  801.                         int i, level = 0;
  802.                         /* UBYTE *ls; */
  803.                         DWORD ls;
  804.  
  805.                         switch (trkinf[Trk].l->totalmode) {
  806.                             case -1:    /* w/o | |n */
  807.                                 trkinf[Trk].total +=
  808.                                     (trkinf[Trk].total - trkinf[Trk].l->totalstart) *
  809.                                     (trkinf[Trk].l->looptime - 1);
  810.                                 break;
  811.                             case 0:        /* w/ | */
  812.                                 trkinf[Trk].total +=
  813.                                         (trkinf[Trk].total - trkinf[Trk].l->totalstart) *
  814.                                     (trkinf[Trk].l->looptime - 2);
  815.                                 break;
  816.                             case 1:        /* w/ |n */
  817.                                 /* no need to add any values */
  818.                                 break;
  819.                         }
  820.  
  821.                         line = line_;
  822.                         ld = ld_;
  823.                         if (trkinf[Trk].l->prev == NULL || (trkinf[Trk].l->prev->prev == NULL && trkinf[Trk].l->loopmode < 0) ) {
  824.                             zmserror("too many :| .",line_,linebuf_,zms_,0,1);
  825.                         }
  826.  
  827.                         ls = (trkinf[Trk].l->loopmode < 0)?        /* |n .. :| :| ? */
  828.                                         trkinf[Trk].l->prev->loopstart :
  829.                                         trkinf[Trk].l->loopstart;
  830.  
  831.                         *trkdata[Trk].zmd++ = 0xCE;
  832.                         trkdata[Trk].zmd += 4;
  833.                         /* tmpDWORD = trkdata[Trk].zmd - ls; */    /* trkinf[Trk].l->loopstart; */
  834.                         tmpDWORD = trkdata[Trk].zmd - trkdata[Trk].zmdbuf - ls;
  835.                                                                 /* trkinf[Trk].l->loopstart; */
  836.                         /* trkdata[Trk].zmd -= 2; */
  837.                         putDword(trkdata[Trk].zmd - 4, tmpDWORD);
  838.                         /* trkdata[Trk].zmd += 2; */
  839.  
  840.                         if (trkinf[Trk].l->loopskip) {    /* exist | or |n ? */
  841.                             putDword(trkdata[Trk].zmdbuf + trkinf[Trk].l->loopskip ,
  842.                                     (trkdata[Trk].zmd - trkdata[Trk].zmdbuf) - trkinf[Trk].l->loopskip - 4);
  843.                             trkinf[Trk].l->loopskip = 0;
  844.                             if (trkinf[Trk].l->loopmode) {    /* |n? */
  845.                                 level = 0;                    /* |n ... :| */
  846.     /* add v0.65 */                if (++trkinf[Trk].l->looptime2 == trkinf[Trk].l->looptime) {
  847.                                     level = 1;
  848.                                 }
  849.                             } else {                        /* | ... :| */
  850.                                 level = 1;
  851.                             }
  852.  
  853.  
  854.                         } else if (trkinf[Trk].l->loopmode == 0) {        /* normal loop :| */
  855.                             level = 1;
  856.                         } else if (trkinf[Trk].l->loopmode < 0) {        /* |n .. :| .. :| */
  857.                             level = 2;
  858.                         }
  859.                         for (i = 0; i < level; i++) {
  860.                             trkinf[Trk].l = trkinf[Trk].l->prev;
  861.                             efree(trkinf[Trk].l->next,"trkinf[Trk].l->next");
  862.                             trkinf[Trk].l->next = NULL;
  863.                         }
  864.  
  865.                                             /* loop is end if it's not | or |n after |n... :| */
  866.                         if (level == 0) {                                    /* |n .. :|  */
  867.                             trkinf[Trk].l->loopmode = -trkinf[Trk].l->loopmode;
  868.                         } else {                                    /* lev == 1: normal :| */
  869.                             /* trkinf[Trk].l->loopmode = 0; */            /* lev == 2: |n ... :| .. :| */
  870.                         }
  871.                     } while (trkinf[Trk].back_repeat && (Trk = trkinf[Trk].cominf->backtrk[Trk]) != -1);
  872.                 }
  873.             } else {
  874.                 zmserror("SYNTAX ERROR",line_,linebuf_,zms_,0,1);
  875.             }
  876.             break;
  877.     }
  878.  
  879.  
  880.     return zms;
  881. }
  882.  
  883.  
  884.  
  885.  
  886.  
  887. UBYTE *makeZmdEigDepthSub(UBYTE *zms,
  888.                         VELOETCVAR *vv, BYTE *pos,BYTE *num,BYTE supplementmode)
  889. {
  890.     int i, paras;
  891.     VELOETCVAR v[17];
  892.     const BYTE lastvpos = *num;
  893.  
  894.     *pos = 0;
  895.     /* zms = getpara(zms, v, ¶s); */
  896.     zms = getpara(zms, v, ¶s, 0);
  897.  
  898.     if (v[0].relflg[0] == 2) {            /* omit 1st parameter */
  899.         if (paras) {                /* continues... */
  900.             vv[0].var[0]    = (supplementmode)? vv[lastvpos].var[0] : 0;
  901.         } else {                    /* that's all */
  902.             *pos = *num = 0;
  903.         }
  904.     } else {                        /* 1st parameter is there */
  905.         WORD velo = v[0].var[0];
  906. #ifdef A
  907.         if (v[0].relflg[0] == 1 && supplementmode) {        /* relative */
  908.             velo += vv[lastvpos].var[0];
  909.         }
  910. #endif
  911. /*
  912. printf("[V=%d]",velo);
  913. */
  914.         vv[0].var[0] = velo;
  915.     }
  916.     vv[0].relflg[0] = v[0].relflg[0];
  917.  
  918.     for (i = 1; i < paras; i++) {    /* next... */
  919.         if (v[i].relflg[0] == 2) {        /* omit Nth parameter */
  920.             vv[i].var[0] = (supplementmode)? vv[i - 1].var[0] : 0;
  921.         } else {
  922.             WORD velo = v[i].var[0];
  923.             if (v[i].relflg[0] == 1 && supplementmode) {
  924.                 velo += vv[i - 1].var[0];
  925.             }
  926. /*
  927. printf("[V=%d]",velo);
  928. */
  929.             vv[i].var[0] = velo;
  930.         }
  931.         vv[i].relflg[0] = v[i].relflg[0];
  932.     }
  933.     *num = paras;
  934.  
  935.     return zms;
  936. }
  937.  
  938.  
  939. UBYTE *makeZmdVeloSeq(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  940.                         TRKINF *trkinf)
  941. {
  942.     int trk;
  943.     char *zms_ = zms;
  944.     DWORD line_ = line;
  945.     LINEDATA *ld_ = ld;
  946.  
  947.     for (trk = 0; target[trk] >= 0; trk++) {
  948.         const int Trk = target[trk];
  949.         int i, paras;
  950.         VELOETCVAR *v;
  951.         const BYTE lastvpos = trkinf[Trk].veloznum - 1;
  952.         const VELOETCVAR lastv = (lastvpos == -1) ? trkinf[Trk].velou : trkinf[Trk].velocity[lastvpos];
  953.         line = line_;
  954.         ld = ld_;
  955.         zms = getvpara(zms_, &v, ¶s);
  956.         trkinf[Trk].velozpos = 0;
  957.         trkinf[Trk].veloseqsw = 1;
  958.  
  959.  
  960.         if (paras) {
  961.             char s[32];
  962.             sprintf(s,"trkinf[%d].velocity",Trk);
  963.             trkinf[Trk].velocity = (VELOETCVAR*)erealloc(trkinf[Trk].velocity, sizeof(VELOETCVAR) * paras,s);
  964.             trkinf[Trk].veloznum = paras;
  965.  
  966.             for (i = 0; i < paras; i++) {
  967.                 if (v[i].relflg[0] == 2) {                                /* omit the 1st/Xth value */
  968.                     if (i > 0) {
  969.                         trkinf[Trk].velocity[i].var[0] = 0x80;
  970.                             /* trkinf[Trk].veloz[i - 1].var[0]; */
  971.                         trkinf[Trk].velocity[i].var[1] = /* 0x80; */
  972.                             trkinf[Trk].velocity[i - 1].var[1];
  973.                     } else {
  974.                         trkinf[Trk].velocity[i] = lastv;
  975.                     }
  976.                 } else {                            /* 1st/Xth value is there */
  977.                     WORD velo = v[i].var[0];
  978.                     if (v[i].relflg[0] == 1) {
  979.                         if (i > 0) {
  980.                             velo += trkinf[Trk].velocity[i - 1].var[0];
  981.                         } else {
  982.                             velo += lastv.var[0];
  983.                         }
  984.                         if (velo > 127) {
  985.                             velo = 127;
  986.                     } else if (velo < 0) {
  987.                             velo = 0;
  988.                         }    
  989.                     }
  990.                     trkinf[Trk].velocity[i].var[0] = velo;
  991.                     trkinf[Trk].velocity[i].var[1] = v[i].var[1];
  992. /* printf("[V=%d]",velo); */
  993.                 }
  994.             }
  995.  
  996.             /* if (paras) { */
  997.                 /*trkinf[Trk].veloseqsw = 1; */
  998.             if (paras) {
  999.                 trkinf[Trk].veloznum = paras;
  1000.             }
  1001.             if (paras == 1) {
  1002.                 int velo    = trkinf[Trk].velocity[0].var[0];
  1003.                 const int r = trkinf[Trk].velocity[0].var[1];
  1004.  
  1005.                 trkinf[Trk].velou.var[0] = velo;
  1006.                 trkinf[Trk].velou.var[1] = r;
  1007.                 if (r) {
  1008.                     velo += rand2(r);
  1009.                 }
  1010.  
  1011.                 velo += trkinf[Trk].veloofst;
  1012.  
  1013.                 if (velo > 127) {
  1014.                     velo = 127;
  1015.                 } else if (velo < 0) {
  1016.                     velo = 0;
  1017.                 }
  1018.  
  1019.                 *trkdata[Trk].zmd++ = 0x93;
  1020.                 *trkdata[Trk].zmd++ = velo;
  1021.             }
  1022.             /* } */
  1023.         }
  1024.         setVelocitySequenceMode(trkinf,Trk,(paras > 1));
  1025.         efree(v,"v");
  1026.  
  1027.         /* trkinf[Trk].veloz[0].relflg[0] = 0; */
  1028.             /* zmserror("velocity sequence error",line,linebuf,zms,0,1); */
  1029.     }
  1030.     return zms;
  1031. }
  1032.  
  1033.  
  1034. UBYTE *makeZmdQuantize(UBYTE *zms, int mode, const BYTE target[],
  1035.                         TRKINF *trkinf)
  1036. {
  1037.     int trk;
  1038.     char *zms_ = zms;
  1039.     DWORD line_ = line;
  1040.     LINEDATA *ld_ = ld;
  1041.  
  1042.     for (trk = 0; target[trk] >= 0; trk++) {
  1043.         const int Trk = target[trk];
  1044.         int i, paras;
  1045.         VELOETCVAR *v;
  1046.         const BYTE lastvpos = trkinf[Trk].quantizenum - 1;
  1047.         const VELOETCVAR lastv = (lastvpos == -1) ? trkinf[Trk].quantize[0] : trkinf[Trk].quantize[lastvpos];
  1048.         char s[32];
  1049.         sprintf(s,"trkinf[%d].quantize",Trk);
  1050.  
  1051.         line = line_;
  1052.         ld = ld_;
  1053.         /* zms = getpara(zms, v, ¶s); */
  1054.         zms = getvpara(zms_, &v, ¶s);
  1055.         trkinf[Trk].quantizepos = 0;
  1056.  
  1057.         if (paras == 0) {
  1058.             paras = 1;
  1059.         }
  1060.         trkinf[Trk].quantize = (VELOETCVAR*)erealloc(trkinf[Trk].quantize, sizeof(VELOETCVAR) * paras,s);
  1061.         trkinf[Trk].quantizenum = paras;
  1062.  
  1063.         for (i = 0; i < paras; i++) {        /* next one... */
  1064.             if (v[i].relflg[0] == 2) {    /* omit Nth parameter */
  1065.                 if (i == 0) {
  1066.                     trkinf[Trk].quantize[0] = lastv;
  1067.                 } else {
  1068.                     trkinf[Trk].quantize[i] = trkinf[Trk].quantize[i - 1];
  1069.                 }
  1070.             } else {
  1071.                 trkinf[Trk].quantize[i] = v[i];
  1072.                 if (mode == 0) {                    /* @q... */
  1073.                     trkinf[Trk].quantize[i].relflg[0] = 1;
  1074.                 } else {                            /* q... */
  1075.                     if (trkinf[Trk].quantize[i].var[0] < 0) {
  1076.                         trkinf[Trk].quantize[i].var[0] = -trkinf[Trk].quantize[i].var[0];
  1077.                         switch (mode) {
  1078.                             case 1:                    /* zmc2old -v1.16 */
  1079.                                 trkinf[Trk].quantize[i].relflg[0] = 3;
  1080.                                 break;
  1081.                             case 2:                    /* zmc2 v1.17 */
  1082.                                 break;
  1083.                             case 3:                    /* V3 compatible */
  1084.                                 if (trkinf[Trk].quantize[i].relflg[0] == 3) {    /* *n */
  1085.                                     trkinf[Trk].quantize[i].relflg[0] = 1;
  1086.                                 } else {
  1087.                                     trkinf[Trk].quantize[i].relflg[0] = 0;
  1088.                                     trkinf[Trk].quantize[i].var[0] += 8;
  1089.                                 }
  1090.                                 break;
  1091.                         }
  1092.                     }
  1093.                 }
  1094.             }
  1095.         }
  1096.         if (paras > 1) {
  1097.             zmserror("quantize sequence can use only for zmc2.",line,linebuf,zms,4,1);
  1098.         }
  1099.         efree(v,"v");
  1100.     }
  1101.     return zms;
  1102. }
  1103.  
  1104.  
  1105.  
  1106.  
  1107. UBYTE *makeZmdManyParas(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
  1108.                         DWORD line_,char *linebuf_,
  1109.                         UBYTE com, UBYTE omitcode,BYTE maxparas,
  1110.                         BYTE parabytes,BYTE omitflg,
  1111.                         char *errmes1, char *errmes2,char *errmes3)
  1112. {
  1113.     VELOETCVAR v[17];
  1114.     UBYTE *zms_ = zms;
  1115.     int tmpINT;
  1116.  
  1117.     zms = getpara(zms,v,&tmpINT,0);
  1118.     if (tmpINT > maxparas || (!omitflg && tmpINT != maxparas)) {
  1119.         zmserror(errmes1,line_,linebuf_,zms_,0,1);
  1120.     } else {
  1121.         int trk;
  1122.  
  1123.         for (trk = 0; target[trk] >= 0; trk++) {
  1124.             int i;
  1125.             const int Trk = target[trk];
  1126.  
  1127.             *trkdata[Trk].zmd++ = com;
  1128.             for (i = 0; i < tmpINT; i++) {
  1129.                 if (v[i].relflg[0] == 2) {        /* omit Nth parameter */
  1130.                     if (omitflg) {
  1131.                         *trkdata[Trk].zmd++ = omitcode;
  1132.                         if (parabytes == 2) {
  1133.                             *trkdata[Trk].zmd++ = omitcode;
  1134.                         }
  1135.                     } else {
  1136.                         zmserror(errmes3,line_,linebuf_,zms_,0,1);
  1137.                     }
  1138.                 } else {
  1139.                     if (v[i].relflg[0] == 1) {    /* relative */
  1140.                         zmserror(errmes2,line_,linebuf_,zms_,0,1);
  1141.                     } else {
  1142.                         if (parabytes == 2) {
  1143.                             putWord(trkdata[Trk].zmd, v[i].var[0]);
  1144.                             trkdata[Trk].zmd += 2;
  1145.                         } else {
  1146.                             *trkdata[Trk].zmd++ = v[i].var[0];
  1147.                         }
  1148.                     }
  1149.                 }
  1150.             }
  1151.             for (i = tmpINT; i < maxparas; i++) {
  1152.                 *trkdata[Trk].zmd++ = omitcode;
  1153.                 if (parabytes == 2) {
  1154.                     *trkdata[Trk].zmd++ = omitcode;
  1155.                 }
  1156.             }
  1157.         }
  1158.     }
  1159.  
  1160.     return zms;
  1161. }
  1162.  
  1163.  
  1164.  
  1165. /* omit flag byte(d0,d1,d2,...) supported */
  1166. UBYTE *makeZmdManyParas2(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
  1167.                         DWORD line_,char *linebuf_,
  1168.                         UBYTE com, BYTE maxparas,
  1169.                         const BYTE parabytes[],BYTE omitflg,BYTE ARCCno,
  1170.                         int space, int times, const int mustover0,
  1171.                         char *errmes1, char *errmes2,char *errmes3)
  1172. {
  1173.     VELOETCVAR v[17];
  1174.     UBYTE *zms_ = zms;
  1175.     int tmpINT;
  1176.     UWORD ob = 0;
  1177.  
  1178.     zms = getpara(zms,v,&tmpINT,mustover0);
  1179.     if (tmpINT > maxparas || (!omitflg && tmpINT != maxparas)) {
  1180.         zmserror(errmes1,line_,linebuf_,zms_,0,1);
  1181.     } else {
  1182.         int trk;
  1183.  
  1184.         for (trk = 0; target[trk] >= 0; trk++) {
  1185.             int i;
  1186.             const int Trk = target[trk];
  1187.             UBYTE *obp;
  1188.  
  1189.             *trkdata[Trk].zmd++ = com;
  1190.             if (ARCCno >= 0) {
  1191.                 *trkdata[Trk].zmd++ = ARCCno * 2;
  1192.             }
  1193.             for (i = 0; i < space; i++) {
  1194.                 trkdata[Trk].zmd++;
  1195.             }
  1196.             obp = trkdata[Trk].zmd++;            /* for omit flag byte */
  1197.             if (maxparas > 8) {
  1198.                 trkdata[Trk].zmd++;
  1199.             }
  1200.  
  1201.             for (i = 0; i < tmpINT; i++) {
  1202.                 ob >>= 1;
  1203.                 if (v[i].relflg[0] == 2) {        /* omit Nth parameter */
  1204.                     if (omitflg) {
  1205.                         if (maxparas > 8) {
  1206.                             ob &= 0xFF;
  1207.                         } else {
  1208.                             ob &= 0x7F;
  1209.                         }
  1210.                     } else {
  1211.                         zmserror(errmes3,line_,linebuf_,zms_,0,1);
  1212.                     }
  1213.                 } else {
  1214.                     if (maxparas > 8) {
  1215.                         ob |= 0x100;
  1216.                     } else {
  1217.                         ob |= 0x80;
  1218.                     }
  1219.                     if (v[i].relflg[0] == 1) {    /* relative */
  1220.                         zmserror(errmes2,line_,linebuf_,zms_,0,1);
  1221.                     } else {
  1222.                         if (parabytes[i] == 1) {
  1223.                             *trkdata[Trk].zmd++ = v[i].var[0] * times;
  1224.                         } else if (parabytes[i] == 2) {
  1225.                             putWord(trkdata[Trk].zmd, v[i].var[0] * times);
  1226.                             trkdata[Trk].zmd += 2;
  1227.                         } else {
  1228.                             trkdata[Trk].zmd +=
  1229.                                 putZvar(trkdata[Trk].zmd, v[i].var[0] * times);
  1230.                         }
  1231.                     }
  1232.                 }
  1233.             }
  1234.             for (i = tmpINT; i < 8; i++) {
  1235.                 ob >>= 1;
  1236.                 if (maxparas > 8) {
  1237.                     ob &= 0xFF;
  1238.                 } else {
  1239.                     ob &= 0x7F;
  1240.                 }
  1241.             }
  1242.             if (maxparas > 8) {
  1243.                 ob >>= 1;
  1244.                 putWord(obp, ob);
  1245.             } else {
  1246.                 *obp = ob;
  1247.             }
  1248.         }
  1249.     }
  1250.  
  1251.     return zms;
  1252. }
  1253.  
  1254. /* omit flag byte(d7,d6,d5,...) supported (for ARCC) */
  1255. UBYTE *makeZmdManyParas2A(UBYTE *zms,TRKCHINF *trkdata,const BYTE target[],
  1256.                         DWORD line_,char *linebuf_,
  1257.                         UBYTE com, BYTE maxparas,
  1258.                         const BYTE parabytes[],BYTE omitflg, BYTE ARCCno,
  1259.                         int mode,
  1260.                         char *errmes1, char *errmes2,char *errmes3)
  1261. {
  1262.     VELOETCVAR v[17];
  1263.     UBYTE *zms_ = zms;
  1264.     int tmpINT;
  1265.     UBYTE ob = 0;
  1266.  
  1267.     zms = getpara(zms,v,&tmpINT,0);
  1268.     if (tmpINT > maxparas || (!omitflg && tmpINT != maxparas)) {
  1269.         zmserror(errmes1,line_,linebuf_,zms_,0,1);
  1270.     } else {
  1271.         int trk;
  1272.  
  1273.         for (trk = 0; target[trk] >= 0; trk++) {
  1274.             int i;
  1275.             const int Trk = target[trk];
  1276.             UBYTE *obp = trkdata[Trk].zmd + 2;
  1277.  
  1278.             *trkdata[Trk].zmd++ = com;
  1279.             *trkdata[Trk].zmd++ = ARCCno * 2;
  1280.             trkdata[Trk].zmd++;                    /* for omit flag byte */
  1281.  
  1282.             for (i = 0; i < tmpINT; i++) {
  1283.                 ob <<= 1;
  1284.                 if (v[i].relflg[0] == 2) {        /* omit Nth parameter */
  1285.                     if (omitflg) {
  1286.                         ob &= 0xFE;
  1287.                     } else {
  1288.                         zmserror(errmes3,line_,linebuf_,zms_,0,1);
  1289.                     }
  1290.                 } else {
  1291.                     ob++;
  1292.                     if (v[i].relflg[0] == 1) {    /* relative */
  1293.                         zmserror(errmes2,line_,linebuf_,zms_,0,1);
  1294.                     } else {
  1295.                         if (parabytes[i] == 1) {
  1296.                             *trkdata[Trk].zmd++ = v[i].var[0];
  1297.                         } else if (parabytes[i] == 2) {
  1298.                             putWord(trkdata[Trk].zmd, v[i].var[0]);
  1299.                             trkdata[Trk].zmd += 2;
  1300.                         } else {
  1301.                             trkdata[Trk].zmd +=
  1302.                                 putZvar(trkdata[Trk].zmd, v[i].var[0]);
  1303.                         }
  1304.                     }
  1305.                 }
  1306.             }
  1307.             for (i = tmpINT; i < 8; i++) {
  1308.                 ob <<= 1;
  1309.                 ob &= 0xFE;
  1310.             }
  1311.             *obp = ob;
  1312.             if (mode >= 0) {
  1313.                 ob >>= 1;
  1314.                 if (mode > 0) {
  1315.                     ob |= 0x80;
  1316.                 }
  1317.                 *obp = ob;
  1318.             }
  1319.         }
  1320.     }
  1321.  
  1322.     return zms;
  1323. }
  1324.  
  1325.  
  1326.  
  1327.  
  1328.  
  1329. UBYTE *makeZmdChord(UBYTE *zms,TRKCHINF *trkdata, const BYTE target[],
  1330.                     TRKINF *trkinf,char extmode,COMMONINF *cominf)
  1331. {
  1332.     int trk;
  1333.     UBYTE *zms_ = zms;
  1334.     DWORD line_ = line;
  1335.     UBYTE *linebuf_ = linebuf;
  1336.     LINEDATA *ld_ = ld;
  1337.     const char sepchr = (extmode)? '\"' : '\'';
  1338.  
  1339.  
  1340.     for (trk = 0; target[trk] >= 0; trk++) {
  1341.         const int Trk = target[trk];
  1342.         BYTE note[9];
  1343.         VELOETCVAR v[9];
  1344.         UWORD step_;    /*  = trkinf[Trk].Step; */
  1345.         UWORD gate_;    /*  = getGate1(target,trkinf,trk,step_); */
  1346.         UWORD gate0;
  1347.         WORD delay = trkinf[Trk].cdelay;
  1348.         WORD ptime = trkinf[Trk].ptime;
  1349.         int i,notes;
  1350.         BYTE *qpos = &(trkinf[Trk].quantizepos);
  1351.         /* const BYTE vnum = trkinf[Trk].veloznum; */
  1352.         /* const BYTE oct = trkinf[Trk].octave; */
  1353.  
  1354.         line = line_;
  1355.         ld = ld_;
  1356.         zms = makePortChord(zms_,Trk,trkinf,cominf,
  1357.                             sepchr,0,v,note,¬es,&step_,&gate_, &gate0,
  1358.                             &delay, &ptime);
  1359.         /* trkinf[Trk].octave = oct; */            /* restore octave */
  1360.         incrementStepCounters(&trkinf[Trk], step_);
  1361. /* fprintf(stderr,"[G=%d]",gate0); */
  1362. /*
  1363. {
  1364. int i = 0;
  1365. fprintf(stderr,"\n[");
  1366. for (i = 0; i < notes; i++) {
  1367. fprintf(stderr,"%.2x ",note[i]);
  1368. }
  1369. fprintf(stderr,"]");
  1370. }
  1371. */
  1372.         trkinf[Trk].cdelay = delay;
  1373.         /* trkinf[Trk].ptime = ptime; */
  1374.         if (delay < 0) {                                /* reverse chord pattern */
  1375.             int i;
  1376.             for (i = 0; i < notes / 2; i++) {
  1377.                 BYTE temp = note[i];
  1378.                 note[i] = note[notes - i - 1];
  1379.                 note[notes - i - 1] = temp;
  1380.             }
  1381.             delay = -delay;
  1382.             zmserror("delay under 0 can use only for zmc3.",line_,linebuf_,zms,4,1);
  1383.         }
  1384.         if (delay) {                                    /* check delay parameter */
  1385.             const DWORD delayall = (notes - 1) * (delay - 1);
  1386.             if (delayall > step_) {
  1387.                 zmserror("delay parameter for the chord is too large (for steptime).",line_,linebuf_,zms_,2,1);
  1388.             } else if (delayall > gate_) {
  1389.                 zmserror("delay parameter for the chord is too large (for gatetime).",line_,linebuf_,zms_,3,1);
  1390.             }
  1391.         }
  1392.  
  1393. /* 和音でタイになるときはgate=0xFFFFになる
  1394.  * タイの先が続く音の場合のみ0xFFFF, さもなくば0x8000 
  1395.  * 例: 'ce'&'eg'なら、cは0x8000, eは0xFFFF
  1396.  *
  1397.  * →とりあえず0x8000で埋めておいて、後で必要なら0xFFFFに置換する
  1398.  */
  1399.         if (gate_ == 0xFFFF) {
  1400.             gate_ = 0x8000;
  1401.         }
  1402.  
  1403.  
  1404.         {
  1405.             WORD velo = 0;
  1406.             BYTE relvelo = 0;
  1407.             int i;
  1408.  
  1409. #ifdef AA
  1410. /* del 0.74 */
  1411.             if (!extmode) {
  1412.                 velo = setVelo0(trkdata,Trk,v[0],&relvelo,trkinf,cominf,step_);
  1413.                 if (trkinf[Trk].veloseqsw) {        /* add v0.74 */
  1414.                     vSeqLoopChk(Trk,trkinf);
  1415.                 }
  1416.             }
  1417. #endif
  1418.             {            /* add v0.74: clear chord-used flag */
  1419.                 CHKCHORD *c_last, *c = trkinf[Trk].c;
  1420.                 do {
  1421.                     c->isclosed = 0;
  1422.                     c_last = c;
  1423.                     c = c->next;
  1424.                 } while (c);
  1425.             }
  1426.  
  1427.             for (i = 0; i < notes; i++) {
  1428.                 int usedchordtone = 0;
  1429.                 CHKCHORD *c_last = NULL, *c = trkinf[Trk].c;
  1430.                 /* BYTE relvelo = 0; */
  1431.                 /* set "velocity sequence" or "special velocity" */
  1432.                 if (i == notes - 1) {
  1433.                     if (gate_ <= 0) {
  1434.                         gate_ = 1;
  1435.                     }
  1436.                 }
  1437.  
  1438.                     velo = setVelo0(trkdata,Trk,v[i],&relvelo,trkinf,cominf,step_);
  1439.                     /* vSeqLoopChk(Trk,trkinf); */        /* velo.seq loop check */
  1440.                 if (extmode) {
  1441.                     if (trkinf[Trk].veloseqsw) {        /* add v0.74 */
  1442.                         vSeqLoopChk(Trk,trkinf);
  1443.                     }
  1444.                 }
  1445. /* fprintf(stderr,"[%d:V=%d/%d/%d]",i,v[i].var[0],v[i].relflg[0],velo); */    
  1446.  
  1447.                 do {    /* add 0.62: scan the chord before */
  1448.                     if (c->note == note[i]) {    /* if there is tie-d tone before */
  1449.                         rewriteGateinChord(trkdata, trkinf, Trk, c, 0xFFFF);
  1450.                         c->gatepos = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  1451.                         usedchordtone = 1;
  1452.  
  1453.                         /* if (gate_ != 0x8000) { */        /* add v0.74 */
  1454.                             c->isclosed = 1;
  1455.                         /* } */
  1456.                         break;
  1457.                     }
  1458.                     c_last = c;
  1459.                     c = c->next;
  1460.                 } while (c);
  1461.                 if (!usedchordtone && gate_ == 0x8000) {    /* no chord before */
  1462.                     DWORD gatepos = trkdata[Trk].zmd - trkdata[Trk].zmdbuf;
  1463.  
  1464.                     c = c_last;
  1465.                     c = addNextChkChord(c, note[i], gatepos, gate0);
  1466.                 }
  1467.  
  1468.                 /* set tonename with "*0&" */
  1469.                 {
  1470.                     UWORD d = (i < notes - 1)? delay : step_;
  1471.                     /* const UWORD g = (gate_ == 0x8000)? 0x8000 + step_ : gate_; */
  1472.                     const UWORD g = gate_;
  1473.                     const int pflg = (i == notes - 1)? 0 : 2;    /* last note? */
  1474.  
  1475.  
  1476. /* fprintf(stderr,"g=%d\n",g); */
  1477.                     zms = setTie2(zms,trkdata,Trk,trkinf,note[i],
  1478.                                     d,g,relvelo,pflg,velo);
  1479.                 }
  1480.                 if (i < notes - 1) {
  1481.                     step_ -= delay;
  1482.                     if (gate_ != 0xFFFF && gate_ != 0x8000) {
  1483.                         gate_ -= delay;
  1484.                     }
  1485.                 }
  1486.             }
  1487. #ifdef A
  1488.             if (gate_ <= 0) {
  1489.                 gate_ = 1;
  1490.             }
  1491.             if (extmode) {
  1492.                 velo = setVelo0(trkdata,Trk,v[notes - 1],&relvelo,trkinf,cominf,step_);
  1493.                 if (trkinf[Trk].veloseqsw) {        /* add v0.74 */
  1494.                     vSeqLoopChk(Trk,trkinf);
  1495.                 }
  1496.             }
  1497.             /* vSeqLoopChk(Trk,trkinf); */            /* velo.seq loop check */
  1498. /*tooslow*/    if (gate_ == 0x8000) {
  1499.                 zms = setTie2(zms,trkdata,Trk,trkinf,note[notes - 1],
  1500.                                 step_,0x8000 + step_,relvelo,0,velo);
  1501.             } else {
  1502.                 zms = setTie2(zms,trkdata,Trk,trkinf,note[notes - 1],
  1503.                                 step_,        gate_ ,relvelo,0,velo);
  1504.             }
  1505. #endif
  1506.  
  1507.             {            /* add v0.74: is tied-tone used?
  1508.                          * 相当処理がmakeZmdNoteやポルタメントには入っていないので
  1509.                          * 今後フォローが必要
  1510.                          */
  1511.                 CHKCHORD *c_last, *c = trkinf[Trk].c;
  1512.                 do {
  1513.                     if (!c->isclosed && c->note != -1) {
  1514.                         CHKCHORD *c_kill = c;
  1515.                         rewriteGateinChord(trkdata, trkinf, Trk, c, 0x8000 + c->gate);
  1516. /* fprintf(stderr,"{%p %p}",c->prev,c->next); */
  1517. /*fprintf(stderr,"[%d]",c->note - 0x3c);*/
  1518.                         c = killChord(c);        /* free 'c' */
  1519.                     }
  1520.                     c_last = c;
  1521.                     c = c->next;
  1522.                 } while (c);
  1523.             }
  1524.             if (gate_ != 0x8000) {    /* non tie */
  1525.                 freeAllChord(trkinf[Trk].c);
  1526.             }
  1527. /* fprintf(stderr,"(t=%d, g=%d)",trkinf[Trk].total,gate_); */
  1528.         }
  1529.         if (++*qpos >= trkinf[Trk].quantizenum) {
  1530.             *qpos = 0;
  1531.         }
  1532.     }
  1533.  
  1534. /*
  1535.  *  { ... 'ceg'}&
  1536.  * なんてのを正しく検出できない(元祖V3も同様)ので、
  1537.  * 先読みをかました方がいいかも
  1538.  */
  1539.  
  1540.     return zms;
  1541. }
  1542.  
  1543.  
  1544. CHKCHORD *addNextChkChord(CHKCHORD *c, BYTE note, DWORD gatepos, DWORD gate)
  1545. {
  1546.     c->next = emalloc(sizeof(CHKCHORD) * 1,"c->next");
  1547.     c->next->prev = c;
  1548.     c = c->next;
  1549.     c->next = NULL;
  1550.     c->note = note;
  1551.     c->gatepos = gatepos;
  1552.     c->isclosed = 1;
  1553.     c->gate = gate;
  1554. /* fprintf(stderr,"(%.2x: total=%d)",c->note,c->total); */
  1555.  
  1556.     return c;
  1557. }
  1558.  
  1559.  
  1560. void rewriteGateinChord(TRKCHINF *trkdata, TRKINF *trkinf,
  1561.                         int Trk,CHKCHORD *c, UWORD gate)
  1562. {
  1563.     UBYTE *CHORDGATEPOS = getChordGatePos(trkdata[Trk].zmdbuf,
  1564.                                 c->gatepos, trkinf[Trk].renpnotes);
  1565. /*
  1566. fprintf(stderr,"{%.2x %.2x %.2x %.2x %.2x %.2x}",
  1567. *(CHORDGATEPOS - 2),
  1568. *(CHORDGATEPOS - 1),
  1569. *(CHORDGATEPOS    ),
  1570. *(CHORDGATEPOS + 1),
  1571. *(CHORDGATEPOS + 2),
  1572. *(CHORDGATEPOS +3));
  1573. */
  1574. /*fprintf(stderr,"[rewrite %x(%x):%X]",
  1575. CHORDGATEPOS - trkdata[Trk].zmdbuf,trkdata[Trk].zmdbuf[CHORDGATEPOS - trkdata[Trk].zmdbuf-2],gate);
  1576. */
  1577.     putWord(CHORDGATEPOS, gate);
  1578. }
  1579.  
  1580.  
  1581. CHKCHORD *killChord(CHKCHORD *c)
  1582. {
  1583.     CHKCHORD *c_kill = c;
  1584.     c->prev->next = c->next;
  1585.     if (c->next) {
  1586.         c->next->prev = c->prev;
  1587.     }
  1588.     c = c->prev;
  1589.     efree(c_kill,"c");
  1590.  
  1591.     return c;
  1592. }
  1593.  
  1594.  
  1595. int checkCommonCommand(UBYTE *zms_,int notes,BYTE note[],UWORD step_,
  1596.                         DWORD line_,char *linebuf_, COMMONINF *cominf)
  1597. {
  1598.     int ret = 0;
  1599.  
  1600.     if (notes == 1 && (note[0] % 12) == 2) {
  1601.         if (step_ == 0 || step_ == cominf->div) {    /* (d0) || (d1) */
  1602.             cominf->debug = (step_)? 1 : 0;
  1603.             ret = 1;
  1604.         } else {
  1605.             zmserror("portament requires 2 tones.",line_,linebuf_,zms_,0,1);
  1606.         }
  1607.     } else {
  1608.         zmserror("portament requires 2 tones.",line_,linebuf_,zms_,0,1);
  1609.     }
  1610.  
  1611.     return ret;
  1612. }
  1613.  
  1614.  
  1615.  
  1616.  
  1617. #ifdef AAA
  1618.  
  1619. UBYTE *makeZmdChordStr(UBYTE *zms, const int Trk,
  1620.                         TRKINF *trkinf,COMMONINF *cominf,
  1621.                         const UBYTE endchar,
  1622.                         VELOETCVAR v[],BYTE note[],int *notes,
  1623.                         UWORD *step_, UWORD *gate_,WORD *delay, WORD *ptime)
  1624. {
  1625.     /* const int Trk = target[trk]; */
  1626.     UWORD step;
  1627.     int i,err,steps = 0;
  1628.     int beforeOctave = trkinf[Trk].octave;
  1629.     DWORD tmpDWORD;
  1630.     const UWORD Step = trkinf[Trk].Step;
  1631.  
  1632.     {
  1633.  
  1634.         /* */
  1635.  
  1636. /* 基本はmajor code(C = 0,4,7)
  1637.  *
  1638.  * 1)音階直後にmがきたら,第2paraを3にする (短3度)
  1639.  *             dimが来たら,(0,4,7)を(0,3,6,9)にする(減3和音+減7度)
  1640.  *             sus4が来たら,第2paraを5にする (メジャートライアド+短7度-3度+完全4度)
  1641.  *
  1642.  * 2)以降Δ7,M7,maj7が来たら,長7度(11)を追加する (長7度)
  1643.  *       ()なしで数値xが来たら,短x度を追加する (短7度など)
  1644.  *       (#5),(+5),augが来る || [n+]だったら,第3paraを8にする
  1645.  *       (♭5),(-5)が来る    || [n-]だったら,第3paraを6にする
  1646.  *
  1647.  * Bm7(-5)を Bφ (減3和音+短7度(m7))
  1648. */
  1649.         /* major code */
  1650. *        { 0, 4, 7, -1 },        /* C  */
  1651. *        { 0, 4, 7, 9, -1 },        /* C6 */
  1652. *        { 0, 4, 7, 11, -1 },    /* CΔ7  CM7  Cmaj7 */
  1653. *        { 0, 4, 8, -1 },        /* C(#5) [C+] Caug */
  1654. *        { 0, 4, 6, -1 },        /* C(-5) [C-] */            /* [C-] */
  1655. *        { 0, 5, 7, -1 },        /* Csus4 */
  1656.  
  1657.         /* minor code */
  1658. *        { 0, 3, 7, -1 },        /* Cm    [C-] */            /* [C-] */
  1659. *        { 0, 3, 7, 9, -1 },        /* Cm6 */
  1660. *        { 0, 3, 7, 11, -1 },    /* CmΔ7 */
  1661.  
  1662.         /* minor 7th code */
  1663. *        { 0, 3, 7, 10, -1 },    /* Cm7 */
  1664.  
  1665.         /* minor 7th (♭5) code */
  1666. *        { 0, 3, 6, 10, -1 },    /* Cm7(-5) */
  1667.  
  1668.         /* Dominant 7th code */
  1669. *        { 0, 4, 7, 10, -1 },    /* C7 */
  1670. *        { 0, 4, 8, 10, -1 },    /* C7(#5) */
  1671. *        { 0, 4, 6, 10, -1 },    /* C7(-5) */
  1672. *        { 0, 5, 7, 10, -1 },    /* C7sus4 */
  1673.  
  1674.         /* diminish code */
  1675. *        { 0, 3, 6, 9, -1 },        /* Cdim */
  1676.  
  1677.  
  1678.         ┌──────────┬────────────────────┐
  1679.         │コード表記          │コード名                                │
  1680.         ├──────────┼────────────────────┤
  1681.   @      │A                  │A                                      │
  1682.   @      │A6                 │Aシックス                              │
  1683.   @      │AMaj7              │Aメジャー・セブンス                    │
  1684.         │AMaj9              │Aメジャー・ナインス                    │
  1685.         │A69                │Aシックス・ナインス                    │
  1686.         │Aaug, A +5        │Aオーグメント                          │
  1687.   @      │A7                 │Aセブンス                              │
  1688.         │A9                 │Aナインス                              │
  1689.         │A11                │Aイレブンス                            │
  1690.         │A13                │Aサーティーンス                        │
  1691.         │A7+5, Aaug7       │Aオーグメント・セブンス                │
  1692.         │A9+5, A9aug       │Aオーグメント・ナインス                │
  1693.         │A7+9               │Aセブン・シャープド・ナインス          │
  1694.         │A +11              │Aシャープド・イレブンス                │
  1695.         │Adim7              │Aディミニッシュド・セブンス            │
  1696.         │Adimj7             │Aディミニッシュド・メジャー・セブンス  │
  1697.         │Adim9              │Aディミニッシュド・ナインス            │
  1698.   @      │Asus4              │Aサスペンディッド・フォー              │
  1699.         │                    │                                        │
  1700.         │Am                 │Aマイナー                              │
  1701.         │Am6                │Aマイナー・シックス                    │
  1702.         │AmMaj7             │Aマイナー・メジャー・セブンス          │
  1703.         │AmMaj9             │Aマイナー・メジャー・ナインス          │
  1704.         │Am69               │Aマイナー・シックス・ナインス          │
  1705.         │Aalt, A -5        │Aアルタード                            │
  1706.         │Am7                │Aマイナー・セブンス                    │
  1707.         │Am9                │Aマイナー・ナインス                    │
  1708.         │Am11               │Aマイナー・イレブンス                  │
  1709.         │Am13               │Aマイナー・サーティーンス              │
  1710.         │A7-5, Aalt7       │Aアルタード・セブンス                  │
  1711.         │A9-5, A9alt       │Aアルタード・ナインス                  │
  1712.         │A7-9               │Aセブン・フラッテッド・ナインス        │
  1713.         │A13(+11), A13(#11)│Aサーティーンス・シャープド・イレブンス│
  1714.         │Am7-5              │Aアルタード・マイナー・セブンス        │
  1715.         │Am9-5              │Aアルタード・マイナー・セブンス        │
  1716.         │Am11-5             │Aアルタード・マイナー・イレブンス      │
  1717.         │A7sus4             │Aセブンス・サスペンディッド・フォー    │
  1718.         └──────────┴────────────────────┘
  1719.  
  1720.  
  1721. #endif